package com.qxgl.qxglt.model;

import java.sql.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import lombok.Data;

@Data
@Table
@Entity
@EntityListeners(AuditingEntityListener.class)
@GenericGenerator(name = "jpa-uuid",strategy = "uuid")
public class Users {

    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @Column(length = 32)
    private String id;//编号
    @Column(unique = true,nullable = false)
    private String loginName;//登录名
    @NotNull
    @Length(min = 6,max = 20)
    private String password;//密码
    @Column(name = "is_lockout",columnDefinition = "char(2) default '否'",insertable = false)
    private String isLockout;//是否锁定,默认“否”
    @CreationTimestamp//自动生成系统时间，格式为yyyy-MM-dd hh:MM:ss
    @LastModifiedDate//最后修改时间
    private Date lastLoginTime;//最后登陆时间
    @CreationTimestamp//自动生成系统时间，格式为yyyy-MM-dd hh:MM:ss
    @Column(updatable = false,nullable = false)
    private Date createTime;//账号创立时间  
    @CreationTimestamp//自动生成系统时间，格式为yyyy-MM-dd hh:MM:ss
    private Date lockTime;//被锁定时间
    @Email
    private String email;//密保邮箱
    @Pattern(regexp = "^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$")
    private String tel;//密保手机号
     // 用户相关角色
     @ManyToMany(cascade = CascadeType.REFRESH)
     @JoinTable(name = "role_user", inverseJoinColumns = @JoinColumn(name = "role_id"), joinColumns = @JoinColumn(name = "users_id"))
     private List<Roles> rolesList;
 





}